package base.arrays;

import java.util.Arrays;
import java.util.Comparator;

public class 女朋友对象排序 {
    public static void main(String[] args) {
        /*
        利用Arrays 的 sort方法进行排序
        属性要求：姓名，年龄，身高
        按照年龄的大小排序，年龄一样时 按身高排序 ，身高一样时 按姓名字母排序
        */
        GirlFriend gf1 = new GirlFriend("xiaoxinxin",18,1.66);
        GirlFriend gf2 = new GirlFriend("dandan",19,1.74);
        GirlFriend gf3 = new GirlFriend("lishishi",19,1.74);

        GirlFriend[] arr = {gf1,gf2,gf3};
        Arrays.sort(arr, new Comparator<GirlFriend>() {
            @Override
            public int compare(GirlFriend o1, GirlFriend o2) {
                double temp = o1.getAge() - o2.getAge();
                temp = temp == 0 ? o1.getHigh() - o2.getHigh() : temp;
                temp = temp == 0 ? o1.getName().compareTo(o2.getName()) : temp;

                if (temp > 0 ){
                    return 1;
                }else if (temp < 0){
                    return -1;
                }else {
                    return 0;
                }
            }
        });

        System.out.println(Arrays.toString(arr));
    }
}

class GirlFriend{
    private String name;
    private int age;
    private double high;

    public GirlFriend(String name, int age, double high) {
        this.name = name;
        this.age = age;
        this.high = high;
    }

    @Override
    public String toString() {
        String rt = getName() + ","+getAge()+","+getAge();
        return rt;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public double getHigh() {
        return high;
    }

    public void setHigh(double high) {
        this.high = high;
    }
}